#include "multicast.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main1(int argc, char **argv) {
    struct multicast_handle mh;
    if (multicast_join(&mh, "225.0.0.1", "192.168.22.29", 3062) == -1) {
        perror("multicast_join");
        return -1;
    }

    char buff[32];
    int ret, i = 0;
    #if 0
    while (1) {
        sprintf(buff, "this is %d message", i++);
        ret = multicast_send(&mh, buff, strlen(buff));
        if (ret <= 0) {
            perror("multicast_send");
            continue;
        }
        sleep(1);
    }
    #else
    while (1) {
        ret = multicast_recv(&mh, buff, 32);
        if (ret <= 0) {
            perror("multicast_recv");
            continue;
        }
        buff[ret] = 0;
        printf("recv %s %d: %s\n", inet_ntoa(mh.remote_addr.sin_addr), ntohs(mh.remote_addr.sin_port), buff);
    }
    #endif
    
    multicast_close(&mh);
    
    return 0;
}